DECLARE @MODIFIED_USER_ID uniqueidentifier

SET @MODIFIED_USER_ID = '00000000-0000-0000-0000-000000000001'

DELETE FROM TERMINOLOGY WHERE NAME = 'LBL_WHEREABOUTS' AND MODULE_NAME = 'Home'

INSERT INTO TERMINOLOGY (DELETED, CREATED_BY, DATE_ENTERED, MODIFIED_USER_ID, DATE_MODIFIED, NAME, LANG, MODULE_NAME, LIST_NAME, LIST_ORDER, DISPLAY_NAME)
VALUES (0, @MODIFIED_USER_ID, getdate(), @MODIFIED_USER_ID, GETDATE(), 'LBL_WHEREABOUTS', 
(SELECT VALUE FROM CONFIG WHERE CONFIG.NAME = 'default_language'), 'Home', null, null, 'Whereabouts Calendar')

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WHEREABOUTS]') AND type in (N'U'))
BEGIN
	CREATE TABLE WHEREABOUTS
	(
		ID uniqueidentifier NOT NULL,
		NAME varchar(250) NOT NULL,
		BEGINDATE datetime NOT NULL,
		ENDDATE datetime NOT NULL,
		DESCRIPTION text NULL,
		LOCATION varchar(250) NULL,
		CONSTRAINT PK_WHEREABOUTS PRIMARY KEY CLUSTERED 
		(
			ID ASC
		)
	)
	ALTER TABLE WHEREABOUTS ADD DEFAULT (newid()) FOR [ID]
END


IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spWHEREABOUTS_Update]') AND type in (N'P', N'PC'))
	DROP PROCEDURE spWHEREABOUTS_Update
GO
-- =============================================
-- Author:		Jake Ginnivan
-- Create date: 7-11-08
-- Description:	
-- =============================================
CREATE PROCEDURE spWHEREABOUTS_Update
	@id uniqueidentifier, 
	@name varchar(250),
	@begindate datetime,
	@enddate datetime, 
	@description text,
	@location varchar(250)
AS
BEGIN
	IF EXISTS (SELECT ID FROM WHEREABOUTS WHERE ID = @id)
		UPDATE WHEREABOUTS
		SET 
			Name = @name,
			BEGINDATE = @begindate,
			ENDDATE = @enddate,
			DESCRIPTION = @description,
			LOCATION = @location
		WHERE ID = @id
    ELSE
    BEGIN
		IF dbo.fnIsEmptyGuid(@id) = 1
			SET @id = NEWID()
		
		INSERT INTO WHEREABOUTS (ID, BEGINDATE, ENDDATE, DESCRIPTION, LOCATION)
		VALUES (@id, @begindate, @enddate, @description, @location)		
    END
END

GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spWHEREABOUTS_Delete]') AND type in (N'P', N'PC'))
DROP PROCEDURE spWHEREABOUTS_Delete
GO

-- =============================================
-- Author:		Jake Ginnivan
-- Create date: 7-11-08
-- Description:	
-- =============================================
CREATE PROCEDURE spWHEREABOUTS_Delete
	@id uniqueidentifier
AS
BEGIN
    DELETE FROM WHEREABOUTS
    WHERE ID = @id
END


GO